<template>
  <div class="activity_new">
    <div>
      <ImgT class="imgs" src="/imgs/activity/new_year.webp" alt="" />
    </div>
    <div class="noticebar">
      <nut-noticebar scrollable class="noticebar_main" :speed="2" color="#ffffff">
        <span v-html="redEnvelopeState.noticeMsg"></span>
      </nut-noticebar>
      <div class="record" @click="openRecord('user')">获奖记录</div>
    </div>
    <div class="balance">
      <img :src="avatarUrl" alt="" class="mr-10" />
      <div class="balance_text">
        <div>
          <span>红包金额</span>
          <span class="num_color">{{
            Intl.NumberFormat().format(redEnvelopeState.redBagInfo?.money)
          }}</span>
        </div>
        <span class="fs_12">完成以下任务，即可领取奖励</span>
      </div>
    </div>
    <div class="content_box">
      <div class="content_box_title">领取任务</div>
      <div class="content_box_main">
        <div v-for="item in redEnvelopeState.taskList" :key="item.task_id">
          <div class="item">
            <div class="item_left">
              <ImgT :src="item.img" :key="item.img" alt="" />
              <div>
                <div :class="[
                  'item_txt',
                  { item_txt_center: ![1, 2, 3].includes(item.task_id) },
                ]">
                  <span v-html="item.label"></span>
                  <iconpark-icon icon-id="Frame" color="#fff" size="1rem" @click="showTipsClick(item)"></iconpark-icon>
                </div>
                <div class="progress_main">
                  <nut-progress :percentage="(item.task_progress / item.task_content) * 100"
                    v-if="[1, 2, 3].includes(item.task_id)" stroke-color="linear-gradient(270deg, #5567FF,#9E1EFF)"
                    stroke-width="15" style="width: 150px" :show-text="false" />
                  <div class="progress_total" v-if="[1, 2, 3].includes(item.task_id)">
                    {{
                      Intl.NumberFormat().format(item.task_progress) +
                      "/" +
                      Intl.NumberFormat().format(item.task_content)
                    }}
                  </div>
                </div>
              </div>
            </div>

            <div class="to_btn" v-if="item.status == '0'" @click="goFollow(item)">
              去完成
            </div>
            <ImgT v-else src="/imgs/activity/success_btn.webp" :key="'success_btn'" alt="" class="success_btn" />
          </div>
        </div>
        <div class="focus_label">
          关注FB，关注FB群，关注TG群后，需人工审核，请
          <span @click="customerService">联系客服</span>
        </div>
      </div>
    </div>
    <!-- 活动规则 -->
    <div class="content_box">
      <div class="content_box_title">活动规则</div>
      <div class="content_box_main content_box_rule">
        <ol v-html="redEnvelopeState.redBagInfo?.rule"></ol>
      </div>
    </div>
    <!-- 分享弹窗 -->
    <shareModal v-model:visible="redEnvelopeState.visible"></shareModal>
    <recordModal ref="recordModalRef" />
    <redBagModal ref="redBagModalRef" :avatarUrl="avatarUrl" />
    <ImgT src="/imgs/activity/record.webp" alt="" :key="'record'" class="my_record" @click="openRecord('my')" />
  </div>
  <div class="btn_group">
    <!-- <nut-button class="btn_1">活动规则</nut-button> -->
    <nut-button class="btn_2" @click="getFunds">立即领取</nut-button>
    <nut-button class="btn_1" @click="submit">{{ t("share") }}</nut-button>
  </div>

  <Modal v-model:visible="showTips" title="说明">
    <div class="tips_content" v-html="tipsInfo"></div>
  </Modal>
  <Toast v-model:visible="redEnvelopeState.showToast">{{
    redEnvelopeState.toast_value
  }}</Toast>
</template>

<script setup lang="ts">
import { onMounted, onUnmounted, reactive, ref } from "vue";
import shareModal from "@/views/me/components/shareModal.vue";
import Toast from "@/components/Toast.vue";
import { useRoute } from "vue-router";
import { useI18n } from "vue-i18n";
import recordModal from "./components/recordModal.vue";
import redBagModal from "./components/redBagModal.vue";
import { avatarUrl, lang, adminI18n } from "@/utils/commonVar";
import { useredEnvelopeHooks, redEnvelopeState } from "./hooks.ts";

const { t } = useI18n();
const route = useRoute();

const recordModalRef: any = ref(null);
const redBagModalRef: any = ref(null);

const state: any = reactive({
  detail: null,
});

const submit = () => {
  redEnvelopeState.visible = true;
};

const {
  receiveRed,
  goFollow,
  customerService,
  showTipsClick,
  showTips,
  tipsInfo,
  getFunds,
  awardRecordClick,
  awardMyRecordClick,
  envelopeEntry,
} = useredEnvelopeHooks();

// 打开领取记录
const openRecord = (type: any) => {
  recordModalRef && recordModalRef.value?.openMpdal(type);
};

onMounted(async () => {
  if (route.query.activty_id) {
    const content = `activities_mobile_content_${route.query.activty_id}`;
    state.detail = adminI18n.value[lang.value][content];
  }
  if (route.query.pic_content) {
    state.detail = route.query.pic_content;
  }

  receiveRed();
  awardRecordClick();
  awardMyRecordClick();
  envelopeEntry();
});
onUnmounted(() => { });
</script>

<style lang="scss" scoped>
.activity_new {
  height: 100%;
  padding: 10px 10px 100px;
  overflow: auto;

  .imgs {
    width: 100%;
  }

  .noticebar {
    margin-top: 6px;
    display: flex;
    align-items: center;
    background: #131232;
    box-shadow: 0.5px 0.5px 1px 0px #2e296b inset;
    border-radius: 8px;

    &:deep(.nut-noticebar__page) {
      background: unset;

      .nut-noticebar__page-lefticon {
        display: none;
      }
    }

    .noticebar_main {
      flex: 1;
    }

    .record {
      width: 80px;
      margin-left: 10px;
      color: #5b6cff;
      text-decoration: underline;
      cursor: pointer;
    }
  }

  .balance {
    width: 100%;
    height: 74px;
    display: flex;
    padding: 0 10px;
    align-items: center;
    border-radius: 8px;
    background: linear-gradient(94.51deg, #fa397e 0%, #ff852d 99.32%);

    img {
      height: 44px;
      width: 44px;
      border: 2px solid #aeacff;
      border-radius: 50%;
    }

    .balance_text {
      display: flex;
      flex-direction: column;
      gap: 6px;
      margin-left: 10px;
      color: #ffffff;
      font-size: 14px;
    }
  }

  .content_box {
    margin-top: 10px;
    width: 100%;

    border-radius: 8px;
    background: #131232;
    overflow: hidden;

    .content_box_title {
      font-weight: 700;
      height: 34px;
      background: #1b1f4b;
      color: #ffffff;
      line-height: 34px;
      padding-left: 10px;
    }

    .content_box_main {
      padding: 12px 11px;
      margin-bottom: 40px;

      .item {
        width: 100%;
        margin-bottom: 10px;
        height: 48px;
        background: #1b1f4b;
        border-radius: 8px;
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0 10px;

        .item_left {
          display: flex;
          color: #ffffff;

          img {
            width: 40px;
            height: 40px;
            margin-right: 8px;
          }

          &:deep(.nut-progress-outer) {
            background-color: #282845;

            .nut-progress-inner {
              background: linear-gradient(90deg,
                  rgba(115, 184, 238, 0.19) 0%,
                  rgba(105, 166, 236, 0.42) 31%,
                  rgba(197, 135, 233, 0.54) 61%,
                  #9e1eff) !important;
            }
          }

          .progress_main {
            position: relative;

            .progress_total {
              position: absolute;
              left: 6px;
              top: 0px;
              font-size: 11px;
            }
          }
        }

        .item_txt {
          display: flex;
          align-items: center;
          margin-bottom: 5px;
          gap: 5px;
          color: #ffffff;

          img {
            width: 40px;
            height: 40px;
          }
        }

        .item_txt_center {
          margin-bottom: unset;
          height: 100%;
        }

        .to_btn {
          height: 32px;
          min-width: 72px;
          border-radius: 8px;
          color: #ffffff;
          text-align: center;
          line-height: 32px;
          background: linear-gradient(180deg, #5567ff 0%, #9e1eff 100%);
        }

        .success_btn {
          height: 32px;
          width: 72px;
        }
      }
    }
  }
}

.btn_group {
  width: 100%;
  position: fixed;
  bottom: 2px;
  display: flex;
  height: 64px;
  align-items: center;
  box-shadow: 0.5px 0.5px 1px 0px #2e296b inset;
  background: var(---, #131232);
  padding-left: 13px;

  gap: 8px;

  .btn_1 {
    height: 44px;
    border-radius: 8px;
    width: 48%;
    background: #282747 !important;
  }

  .btn_2 {
    height: 44px;
    border-radius: 8px;
    width: 48%;
  }
}

.submit {
  width: 95%;
  height: 44px;
  border-radius: 8px;
  position: fixed;
  bottom: 2px;
  left: 2.5%;
}

.fs_12 {
  font-size: 12px;
}

.num_color {
  margin-left: 5px;
  color: #ffe141;
}

ol {
  color: #ffffff;
  font-size: 12px;

  li {
    margin-bottom: 6px;
  }
}

.my_record {
  position: fixed;
  right: 10px;
  bottom: 70px;
  height: 50px;
}

.focus_label {
  color: #ffffff;
  font-size: 12px;

  span {
    color: #5b6cff;
    text-decoration: underline;
    cursor: pointer;
  }
}

.tips_content {
  padding-top: 30px;

  color: #ffffff;
  font-size: 14px;
  text-align: center;
}

.content_box_rule {
  &:deep() {
    span {
      background-color: transparent !important;
      color: #ffffff !important;
      font-size: 14px !important;
    }
  }
}
</style>
